<template>
  <div style="height:100%;">
    <!-- 侧边栏 -->
    <el-menu
      background-color="#545c64"
      text-color="#fff"
      active-text-color="#ffd04b"
      style="height:100%;"
      router
      :collapse="isCollapse"
      :collapse-transition="false"
      :unique-opened="true"
      :default-active="defaultActive"
    >
      <template v-for="item in items">
        <template v-if="!item.subs">
          <el-menu-item @click="saveTag(item)" :index="item.index" :key="item.index">
            <i class="el-icon-s-order"></i>
            <span slot="title">{{ item.title }}</span>
          </el-menu-item>
        </template>
        <template v-else>
          <el-submenu :index="item.index" :key="item.index">
            <template slot="title">
              <i :class="item.icon"></i>
              <span>{{item.title}}</span>
            </template>
            <template v-for="item2 in item.subs">
              <template v-if="!item2.subs">
                <el-menu-item @click="saveTag(item2)" :index="item2.index">
                  <template slot="title">
                    <i class></i>
                    <span>{{item2.title}}</span>
                  </template>
                </el-menu-item>
              </template>
              <template v-else>
                <el-submenu :index="item2.index">
                  <template slot="title">
                    <span>{{item2.title}}</span>
                  </template>
                  <el-menu-item
                    @click="saveTag(item3)"
                    v-for="(item3,index3) in item2.subs"
                    :key="index3"
                    :index="item3.index"
                  >
                    <template slot="title">
                      <i class></i>
                      <span>{{item3.title}}</span>
                    </template>
                  </el-menu-item>
                </el-submenu>
              </template>
            </template>
          </el-submenu>
        </template>
      </template>
    </el-menu>
  </div>
</template>

<script>
export default {
  // 组件名称
  name: "demo", // 组件参数 接收来自父组件的数据
  props: [],
  components: {},
  data() {
    return {
      items: [
        {
          icon: "el-icon-lx-home",
          index: "dashboard",
          title: "系统首页"
        },
        {
          icon: "el-icon-lx-cascades",
          index: "table",
          title: "基础表格"
        },
        {
          icon: "el-icon-lx-copy",
          index: "tabs",
          title: "tab选项卡"
        },
        {
          icon: "el-icon-lx-calendar",
          index: "3",
          title: "表单相关",
          subs: [
            {
              index: "form",
              title: "基本表单"
            },
            {
              index: "3-2",
              title: "三级菜单",
              subs: [
                {
                  index: "editor",
                  title: "富文本编辑器"
                },
                {
                  index: "markdown",
                  title: "markdown编辑器"
                }
              ]
            },
            {
              index: "upload",
              title: "文件上传"
            }
          ]
        },
        {
          icon: "el-icon-lx-emoji",
          index: "icon",
          title: "自定义图标"
        },
        {
          icon: "el-icon-pie-chart",
          index: "charts",
          title: "schart图表"
        },
        {
          icon: "el-icon-rank",
          index: "6",
          title: "拖拽组件",
          subs: [
            {
              index: "drag",
              title: "拖拽列表"
            },
            {
              index: "dialog",
              title: "拖拽弹框"
            }
          ]
        },
        {
          icon: "el-icon-lx-global",
          index: "i18n",
          title: "国际化功能"
        },
        {
          icon: "el-icon-lx-warn",
          index: "7",
          title: "错误处理",
          subs: [
            {
              index: "permission",
              title: "权限测试"
            },
            {
              index: "404",
              title: "404页面"
            }
          ]
        },
        {
          icon: "el-icon-lx-redpacket_fill",
          index: "/donate",
          title: "支持作者"
        }
      ]
    };
  },
  computed: {
    isCollapse() {
      return this.$store.state.isCollapse;
    },
    defaultActive() {
      return this.$store.state.defaultActive;
    }
  },
  watch: {},
  methods: {
    saveTag(info) {
      this.$store.commit("saveTag", info);
    },
    setDefaultTag() {
      this.$store.commit("saveTag", this.items[0]);
    }
  },
  beforeCreate() {},
  created() {
    this.setDefaultTag();
  },
  beforeMount() {},
  mounted() {}
};
</script> 
<style scoped>
.el-menu {
  border-right: 0;
}
</style>
